layui.use(['layer','form', 'util', 'element'], function() {
  	var $ = layui.jquery,
    layer = layui.layer,
    element = layui.element(),
    util = layui.util;
     var form = layui.form();
    
  /**
   * 使用内部工具组件
   */
  util.fixbar();
  /**
   ****************************jq扩展函数*******************************v**
   */
  $.ajax({
  	type:"get",
  	url:url+'/ic-iot/users/'+userId,
  	dataType : 'json',
	async:false,
	contentType: "application/json; charset=utf-8",
	beforeSend: function(request) {
        request.setRequestHeader("accessToken", accessToken);
    },
	success : function(data) {
		
		if(data['code'] == 1){
			$("#userPhone").val(data.result.userPhone);
			$("#userName").val(data.result.userName);
			$("#userEmail").val(data.result.userEmail);
			$("#companyName").val(data.result.companyName);
			if(data.result.alarmFlag == 1){
					$("#on").attr('checked','checked');
					form.render();
			}else{
				$("#off").attr('checked','checked');
				form.render();
			};
			if(data.result.jpushFlag == 1){
				$("#onjpushFlagStr").attr('checked','checked');
				form.render();
			}else{
				$("#offjpushFlagStr").attr('checked','checked');
				form.render();
			}
			
		}else{
			ifajax(data);
		}
	}
  });
  //表单提交
   form.on('submit(useradd)', function(data){
	   var data = formToJson($("#user-add"));
		$.ajax({
			type:"put",
			url: url +'/ic-iot/users/'+userId,
			data:data,
			dataType : 'json',
			async:false,
			contentType: "application/json; charset=utf-8",
			beforeSend: function(request) {
	            request.setRequestHeader("accessToken", accessToken);
	        },
			success : function(data) {
				if(data['code'] == 1){
					layer.msg(data['description']);
					
					setTimeout(function(){
						layer_close();
						window.parent.location.reload();
					},2000);
				}else{
					ifajax(data);
				}
			}
		});
	    return false;
  });
  

});